import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * 
 */

/**
 * @author scottd
 *
 */
public class User {
	
	protected String name;
	protected String emailAddress;
	
	protected User(String name, String emailAddress){
		this.name = name;
		this.emailAddress = emailAddress;
	}
	
	protected User (){
		this.name = "No name entered";
		this.emailAddress = "No email address given";
	}
	
	//mutators 
	
	protected void setName(String name){
		this.name = name;
	}
	
	protected void setEmail( String email){
		this.emailAddress = emailAddress;
	}
	
	//accessors
	protected String getName(){
		return this.name;
	}
	protected String getEmail(){
		return this.emailAddress;
	}
	
	// helper methods
	public static boolean verifyUser(String userName, char userType){
		String temp = "";
		String first, last = "";
		char mI = ' ';
		
		try{
			Scanner scan = new Scanner(new File("RegisteredUsers.dat"));
			while (scan.hasNextLine()){
				temp = scan.nextLine();
				last = temp.substring(9,24).trim();
				first = temp.substring(24,39).trim();
				mI = temp.substring(39,40).charAt(0);
				
				
				if (temp.charAt(40) == userType && (last + ", " + first + " " + mI + ".").equalsIgnoreCase(userName) ){
					return true;
				}
			
			}
			scan.close();
			
		}catch(FileNotFoundException fnfe){
			System.err.println("RegisteredUsers.dat not found in the database! Please consult admin!");
			System.exit(1);
		}
		
		return false;
	}
	

}
